#include "stdafx.h"
#include "config.h"
#include "debug.h"

#include "multiscalesubimage.h"
#include "deepzoomimagetilesource.h"

namespace DeepZoomImage
{
	MultiScaleSubImage::MultiScaleSubImage()
		: refcount(1)
	{
		source = NULL;	
	}

	MultiScaleSubImage::MultiScaleSubImage( DeepZoomImageTileSource *tsource, int _id, int _n)
		: m_AspectRatio(1.0)
		, m_Opacity(1.0)
		, m_ViewportOrigin(0, 0)
		, m_ViewportWidth(1.0)
		, m_ZIndex(0)
		, refcount(1)
	{
		LOG_MSI ("new MultiScaleSubImage ()\n");
		source = tsource;
		source->ref();
		id = _id;
		n = _n;
	}

	MultiScaleSubImage::~MultiScaleSubImage ()
	{
		if (source)
			source->unref ();
	}

	void MultiScaleSubImage::ref()
	{
		refcount++;
	}
	void MultiScaleSubImage::unref()
	{
		refcount--;
		if ( refcount == 0 ) {
			delete this;
		}
	}

	double MultiScaleSubImage::GetViewportHeight ()
	{
		return GetAspectRatio () * GetViewportWidth ();
	}
};
